package TCP;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;



public class SocketClient_demo {
public static void main(String[] args) throws UnknownHostException, IOException {

	FileInputStream fis=new FileInputStream("D:\\give.jpg");//当前上传文件位置
	Socket socket=new Socket("127.0.0.1",8888);//发送IP和端口地址
	OutputStream os=socket.getOutputStream();//创建Socket输出流
	int len=0;
	byte[]bytes=new byte[1024];
	while((len=fis.read(bytes))!=-1) {os.write(bytes,0, len);}
	
	socket.shutdownOutput();//关闭Socket输出流 服务器结束接受访问
	
	InputStream is=socket.getInputStream();//得到服务器的返回 创建对应IO输入流
	while((len=is.read(bytes))!=-1)
	{System.out.println(new String(bytes,0,len));}//控制台上显示对应返回信息
	fis.close();
	socket.close();
}
}
